set gpChapterTitleCastnum to the number of cast "ChapterTitle"
set gpChapterTextNormalColor to the foreColor of cast "ChapterNormalColor"
set gpChapterTextHiliteColor to the foreColor of cast "ChapterHiliteColor"
set gpChapterTextFlashColor to the foreColor of cast "ChapterFlashColor"
set gpLastString to EMPTY
set gpLastOffset to 0
if gCPU = #mac then
set gpChapterTextPath to gCDvolume & ":data:topics:text:"
set gpChapterVideoPath to gCDvolume & ":data:topics:video:"
else
set gpChapterTextPath to gCDvolume & "\data\topics\text\"
set gpChapterVideoPath to gCDvolume & "\data\topics\video\"
end if
end
on initChapterDatabase
set gpChapterDatabase to ["getting": "Choosing a Dog", "home": "Bringing Your Dog Home", "training": "Training & Obedience", "feeding": "Feeding & Nutrition", "grooming": "Grooming", "healthy": "Preventative Care", "illness": "Illnesses & Ailments", "medical": "Medical Treatment", "work": "Dogs at Work", "shows": "Dog Shows", "travel": "Travel & Boarding", "evolutio": "Evolution", "anatomy": "Anatomy", "behavior": "Behavior", "breeding": "Breeding"]
set gpChapterDatabaseCount to count(gpChapterDatabase)
end
on initTopicsVideoDatabase
set gpTopicsVideoDatabase to ["Advanced Obedience and Stunts": "stunts", "Animal Shelters": "shelter", "Brushing Your Dog": "brushing", "Canine Companions for Independence": "cci", "Cleaning the Eyes and Ears of a Dog": "eyesears", "Dogs as Police Assistants": "police", "Dogs Herding": "herding", "Dogs Hunting": "hunting", "Guide Dogs for the Blind": "guide", "High-Flying Dogs": "flying", "Land Rescue": "landresc", "Obedience": "obedienc", "Schutzhund": "schutz", "Sledding Activities": "sledding", "Teaching Your Dog to Come": "come", "Teaching Your Dog to Lie Down": "down", "Teaching Your Dog to Heel": "heel", "Teaching Your Dog to Sit": "sit", "Teaching Your Dog to Stay": "stay", "Water Rescue": "waterres", "Your Dog's Teeth": "teeth"]
set gpTopicsVideoDatabaseCount to count(gpTopicsVideoDatabase)
end
on enterChapter
setHelpContext("topics")
setTopicsMarker(getChapterMarker())
safePuppetSprite(gpChapterTextSprite, 1)
setChapter(gpChapterIndex)
set gpLastOffset to 0
end
on exitChapter
puppetSprite(gpChapterTextSprite, 0)
end
on getChapterMarker
return gpChapterMarker
end
on handleChapterSelection theSprite
set theCode to the name of cast castNumOfSprite(theSprite)
set gpChapterIndex to findPos(gpChapterDatabase, theCode)
set gJumpMarker to getChapterMarker()
go(the frame + 1)
end
on handleChapterNext
if gpChapterIndex = gpChapterDatabaseCount then
set gJumpMarker to getGlossaryMarker()
set gpChapterIndex to gpChapterIndex + 1
go(the frame + 1)
exit
end if
if getTopicsMarker() = getTOCMarker() then
set gJumpMarker to getChapterMarker()
set gpChapterIndex to 1
go(the frame + 1)
exit
end if
set gpChapterIndex to gpChapterIndex + 1
set gJumpMarker to getChapterMarker()
go(the frame + 1)
end
on handleChapterPrev
if gpChapterIndex = 1 then
set gJumpMarker to getTOCMarker()
go(the frame + 1)
exit
end if
if getTopicsMarker() = getGlossaryMarker() then
set gJumpMarker to getChapterMarker()
set gpChapterIndex to gpChapterDatabaseCount
go(the frame + 1)
exit
end if
set gpChapterIndex to gpChapterIndex - 1
set gJumpMarker to getChapterMarker()
go(the frame + 1)
end
on setChapter theIndex
set theFileCode to getPropAt(gpChapterDatabase, theIndex)
set theCastnum to the number of cast (theFileCode & ".txt")
set the castNum of sprite gpChapterTextSprite to theCastnum
put EMPTY before char 1 of field theCastnum
set theTitle to gpChapterIndex & "." && getaProp(gpChapterDatabase, theFileCode)
set the text of cast gpChapterTitleCastnum to theTitle
end
on handleChapterSearch
waitCursor()
set theCastnum to castNumOfSprite(gpChapterTextSprite)
set theText to the text of cast theCastnum
set totalChars to length(theText)
openXLib(gMiscXObjName)
set dialog to MISC_X(mnew)
pointerCursor()
if not objectp(dialog) then
alert("Sorry - Cannot create Search dialog.")
return
end if
set theMsg to "Enter the word or phrase that you would like to find in this chapter."
set searchString to dialog(mAsk, theMsg, gpLastString, "Find", "Cancel")
updateStage()
if searchString = "Cancel" then
closeXLib(gMiscXObjName)
exit
end if
autoWaitCursor()
if searchString <> gpLastString then
set gpLastString to searchString
set gpLastOffset to 0
end if
set theOffset to offset(searchString, char gpLastOffset + 1 to totalChars of theText)
if theOffset = 0 then
set gpLastOffset to 0
set theOffset to offset(searchString, char gpLastOffset + 1 to totalChars of theText)
if theOffset = 0 then
alert("Could not find" && QUOTE & searchString & QUOTE && "in this chapter.")
dialog(mdispose)
closeXLib(gMiscXObjName)
exit
end if
end if
set theOffset to gpLastOffset + theOffset
set gpLastOffset to theOffset
set thePoint to min(theOffset + 100, the number of chars in field theCastnum)
put EMPTY before char thePoint of field theCastnum